unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls, math, windows;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Image1: TImage;
    Label1: TLabel;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);

    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Timer1Timer(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;
  x1,y1,x2,y2:Integer;
  p:integer;

implementation

{$R *.lfm}

{ TForm1 }



procedure LoadPic();
var
  pic:TPicture;
begin
  pic:=TPicture.Create;
  pic.LoadFromFile('./1.png');
  form1.Image1.Picture:=pic;
  pic.free;
end;

procedure getpic();
begin
     winexec(pchar('adb shell screencap -p /sdcard/1.png'),sw_hide);
     sleep(1000);
     winexec(pchar('adb pull /sdcard/1.png .'),sw_hide);
     sleep(500);
end;

procedure play();
var
   l:double;
   vx:integer;
   vy:integer;
begin
     //坐标与时间
    l:=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    l:=l*StrToFloat(form1.Edit1.Text);

    //vx : 350 - 450
    //vy : 850 - 950
    vx :=350 + Random(100);
    vy := 850 + random(100);

    winexec(pchar('adb shell input swipe '+ inttostr(vx) + ' ' + inttostr(vy) + ' ' +
                       inttostr(vx) + ' ' + inttostr(vy) + ' ' +
                       inttostr(trunc(l))),sw_hide);
    try
       form1.timer1.Interval:=strtoint(form1.edit1.Text);
    except
        form1.timer1.Interval:=3000;
    end;

    Form1.Timer1.Enabled:=true;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   if p= 1 then
      begin
        x1:=x;
        y1:=y;
        p:=2;
      end

   else if p=2 then
     begin
       x2:=x;
       y2:=y;
       p:=3;
       play();
     end;
end;
procedure x();
begin
   getpic();
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     x();
     LoadPic();
     p:=1;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
begin
    Timer1.Enabled:=false;
    x();
     LoadPic();
     p:=1;

end;

end.

